Skip to content

Conversation

@loicguillois
Copy link
Collaborator

@loicguillois loicguillois commented Jan 8, 2026

Problème

L'upload de certains shapefiles échoue avec l'erreur :

The value of "offset" is out of range. It must be >= 0 and <= 1020. Received 515396116

De plus, les coordonnées importées ne sont pas converties en WGS84 (lat/lng), ce qui empêche l'affichage correct des périmètres sur la carte.

Cause

  1. Null Shapes : La bibliothèque shpjs ne gère pas les Null Shapes (type 0)
  2. Projection : Les coordonnées projetées (Lambert 93, UTM) ne sont pas converties en WGS84

Solution

1. Remplacement de shpjs par shapefile

La bibliothèque shapefile gère correctement les Null Shapes en retournant des features avec geometry: null que nous filtrons.

2. Ajout de la reprojection automatique

  • Lecture du fichier .prj pour détecter la projection source (format WKT)
  • Détection automatique de la projection à partir des plages de coordonnées si .prj absent
  • Reprojection vers WGS84 avec proj4

Projections supportées :

Code Description
EPSG:2154 Lambert 93 (France métropolitaine)
EPSG:2975 RGR92 / UTM zone 40S (Réunion)
EPSG:5490 RRAF 1991 / UTM zone 20N (Martinique)
EPSG:32620 WGS84 / UTM zone 20N (Guadeloupe)
EPSG:2972 RGFG95 / UTM zone 22N (Guyane)
EPSG:4471 RGM04 / UTM zone 38S (Mayotte)

Fichiers modifiés

  • server/src/controllers/geoController.ts : Parsing shapefile + reprojection
  • server/package.json : Ajout de proj4

Scripts de diagnostic

  • tools/analyze-shapefile.ts - Analyse détaillée d'un shapefile
  • tools/test-shapefile-fix.ts - Test avant/après pour le fix Null Shapes
  • tools/test-reprojection.ts - Test de reprojection des coordonnées

Tests

# Test parsing Null Shapes
npx tsx tools/test-shapefile-fix.ts "tools/perimetre ACV.zip"

# Test reprojection
npx tsx tools/test-reprojection.ts "tools/perimetre ACV.zip"

Remarque importante

⚠️ La détection automatique de projection est basée sur les plages de coordonnées et peut être imprécise. Pour garantir une reprojection correcte, incluez toujours un fichier .prj dans le shapefile.

Replace shpjs with shapefile library for parsing uploaded shapefiles.
shpjs crashes with "offset out of range" error when encountering
Null Shapes (type 0), which are valid but empty geometry records.

The shapefile library correctly handles these by returning features
with null geometry, which we now filter out before processing.

Also add diagnostic tools for analyzing problematic shapefiles.
@tristanrobert
Copy link
Contributor

tristanrobert commented Jan 8, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@notion-workspace
Copy link

Add proj4 library to reproject shapefile coordinates from projected
coordinate systems (Lambert 93, UTM zones for DOM-TOM) to WGS84.

- Detect projection from .prj file (WKT format)
- Auto-detect projection from coordinate ranges when .prj is missing
- Support common French projections: EPSG:2154, 2975, 5490, 32620, 2972, 4471
- Add test script for verifying reprojection
…ections

Some shapefiles from Réunion use a modified coordinate system with
additional offsets (X+1.35M, Y+1.57M on top of standard UTM 40S).
This causes coordinates to appear in the ocean when reprojected.

Added REUNION_OFFSET projection detection for coordinates in range
X: 1.6M-1.9M, Y: 9.0M-9.5M, which applies the necessary offsets
before UTM 40S reprojection.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 8, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
9.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants